/** 
 
*/
import React, { PureComponent } from 'react';
import { ModalC } from '@/src/comps';
import { Form } from '@ant-design/compatible';
import '@ant-design/compatible/assets/index.css';
import { message } from 'antd';
import { connect } from 'dva';
import SppiJudgmentBasis from './sppiJudgmentBasis';
import 'moment/locale/zh-cn';

@Form.create()
class sppiJudgmentBasis extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      bond: 1,
      loading: false,
      superMan: localStorage.getItem('antd-pro-superMan') == 'true',
      defaultTenant: localStorage.getItem('antd-pro-tenant'),
      initialTenantId: null,
    };
  }

  componentDidMount() {
    // this.setState({ initialTenantId: this.props.tenantId })
  }

  UNSAFE_componentWillReceiveProps(nextProps) {
    if (nextProps.tenantId != this.props.tenantId) {
      this.setState({ initialTenantId: nextProps.tenantId });
    }
  }

  onOk = () => {
    this.setState({
      loading: true,
    });
    const { bond, tenantId } = this.props.form.getFieldsValue();
    let payload = {};
    payload.bond = bond;
    if (tenantId) {
      payload.tenantId = tenantId;
      this.setState({
        initialTenantId: tenantId,
      });
    }

    this.props.dispatch({
      type: 'sppiTestRecordM/updateConf',
      payload: payload,
      callback: (res) => {
        if (res != 'fail') {
          message.success('修改成功');
        }
        this.setState({
          loading: false,
        });
        this.props.onCancel && this.props.onCancel();
      },
    });
  };

  onCancel = () => {
    const { tenantId } = this.props.form.getFieldsValue();
    if (tenantId) {
      this.setState({
        initialTenantId: tenantId,
      });
    }
    this.props.onCancel && this.props.onCancel();
  };

  render() {
    const { visible = false, onCancel = () => {}, otherModel, form, tenantId } = this.props;

    return (
      <ModalC
        title={'SPPI判断依据'}
        visible={visible}
        confirmLoading={this.state.loading}
        onOk={this.onOk}
        onCancel={this.onCancel}
        destroyOnClose={true}
        width={400}
        {...otherModel}
      >
        <SppiJudgmentBasis onCancel={onCancel} form={form} tenantId={this.state.initialTenantId} />
      </ModalC>
    );
  }
}
export default connect(({ sppiTestRecordM, loading }) => ({
  sppiTestRecordM,
  loading,
}))(sppiJudgmentBasis);
